package com.ce.pms.renovation.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.charge.dao.IChargeRecordDao;
import com.ce.pms.charge.service.IChargeRecordProcessor;
import com.ce.pms.charge.service.IParameterDefService;
import com.ce.pms.charge.service.ITransactionService;
import com.ce.pms.charge.vo.ChargeRecordVO;
import com.ce.pms.charge.vo.CreditTransVO;
import com.ce.pms.charge.vo.DebitTransVO;
import com.ce.pms.charge.vo.DepositTransVO;
import com.ce.pms.charge.vo.ParameterDefVO;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.renovation.dao.IDepositAccountingDao;
import com.ce.pms.renovation.dao.IPassChargeItemDao;
import com.ce.pms.renovation.dao.IRenovateChargeItemDao;
import com.ce.pms.renovation.dao.IRenovateRequisitionDao;
import com.ce.pms.renovation.model.DepositAccountingDO;
import com.ce.pms.renovation.model.PassChargeItemDO;
import com.ce.pms.renovation.model.PassDO;
import com.ce.pms.renovation.model.RenovateChargeItemDO;
import com.ce.pms.renovation.model.RenovateRequisitionDO;
import com.ce.util.BeanUtil;

/**
 * 装修费用处理器
 */
public class RenovateChargeRecordProcessorImpl extends PmsBaseServiceImpl implements IChargeRecordProcessor {

	private IChargeRecordDao chargeRecordDao;
	private IDepositAccountingDao depositAccountingDao;
	private IParameterDefService parameterDefService;
	private IPassChargeItemDao passChargeItemDao;
	private IRenovateChargeItemDao renovateChargeItemDao;
	private IRenovateRequisitionDao renovateRequisitionDao;
	private ITransactionService transactionService;

	public Boolean deleteChargeRecord(ChargeRecordVO chargeRecordVO) {
		throw new BusinessException("renovate:renovate_biz_not_implement",BusinessException.ERROR);
	}

	public ChargeRecordVO editChargeRecord(ChargeRecordVO chargeRecord) {
		throw new BusinessException("renovate:renovate_biz_not_implement",BusinessException.ERROR);
	}

	public List<ChargeRecordVO> editChargeRecordBatch(Long operator, List<ChargeRecordVO> chargeRecordVos) {
		throw new BusinessException("renovate:renovate_biz_not_implement",BusinessException.ERROR);
	}

	/**
	 * 功能描述:<br>
	 * @param accountHouseId
	 * @param operator
	 * @param businessCodeId
	 * @param chargeRecords
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Boolean handleChargeRecords(Long accountHouseId, Long operator, Long businessCodeId, List<ChargeRecordVO> chargeRecords) {
		//根据业务类型进行分类，并以业务类型做为KEY，List做为value
		Map<String,List<ChargeRecordVO>> chargeRecordMap=assortChargeRecords(chargeRecords);

		//装修许可证收费
		handleRenovateLicenceCharge(accountHouseId, businessCodeId,operator, chargeRecordMap.get(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN));

		//装修出入证收费
		handleRenovatePassInCharge(accountHouseId, businessCodeId,operator,chargeRecordMap.get(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_C));

		//装修出入证退费
		handleRenovateReturnCharge(accountHouseId, businessCodeId,operator,chargeRecordMap.get(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_R));

		//装修保证金核算
		handleRenovateDeposit(accountHouseId, businessCodeId,operator,chargeRecordMap.get(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_DEPOSIT));

		return true;
	}


	public ChargeRecordVO monthBalance(ChargeRecordVO chargeRecordVO) {
		throw new BusinessException("renovate:renovate_biz_not_implement",BusinessException.ERROR);
	}



	/**
	 * 功能描述:保证金抵冲<br>
	 * 1）保证金帐户增加一笔抵冲交易
	 * 2）物业帐户增加一笔应收交易
	 * 3）物业帐户增加一笔实收交易
	 * 4）建产抵冲与实收交易关系
	 * 5）建立实收与应收交易关系
	 * @param payBizId
	 * @param operator
	 * @param item<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addDepositOffsetTran(Long payBizId, Long operator,Long accountHouseId, ChargeRecordVO item) {
		DepositTransVO depositTransVO=new DepositTransVO();
		Long createor = operator;		//创建人ID
		BigDecimal sum = item.getSum();		//费用金额
		Long debitBusinessId = item.getBusinessId(); //应收交易码
		Long creditBusinessId = payBizId; //支付交易码
		Long houseId = item.getHouseId();//
		Long offsetBusinessId = getDepositAGABusinessId();//保证金抵冲交易码

		depositTransVO.setCreator(createor);
		depositTransVO.setBusinessId(offsetBusinessId);
		depositTransVO.setCredit(sum);
		depositTransVO.setAccountHouseId(accountHouseId);
		depositTransVO.setRemark(item.getRemark());
		depositTransVO.setHouseId(houseId);

		transactionService.offsetOneDepositCharge(debitBusinessId, creditBusinessId, depositTransVO);
	}

	/**
	 * 功能描述:保证金添加一笔交易<br>
	 * @param payBizId
	 * @param operator
	 * @param item<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private DepositTransVO addDepositTran(Long payBizId, Long operator, Long accountHouseId,ChargeRecordVO item) {
		DepositTransVO depositTransVO=new DepositTransVO();
		Long createor = operator;		//创建人ID
		BigDecimal sum = item.getSum();		//费用金额
		Long houseId = item.getHouseId(); //房号

		depositTransVO.setCreator(createor);
		depositTransVO.setBusinessId(payBizId);
		depositTransVO.setCredit(sum);
		depositTransVO.setAccountHouseId(accountHouseId);
		depositTransVO.setHouseId(houseId);
		depositTransVO.setRemark(item.getRemark());
		transactionService.addDepositCharge(depositTransVO);
		return depositTransVO;
	}

	/**
	 * 功能描述:增加一笔应收交易，同时增加一笔支付交易<br>
	 * @param houseId
	 * @param item<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addPropertyTran(Long houseId, Long payBizId, ChargeRecordVO item,Long operator) {
		DebitTransVO debitTransVO = createDebitTran(houseId, item,operator);
		debitTransVO.setRemark(item.getRemark());
		CreditTransVO creditTransVO = createCreditTran(houseId, payBizId, item, debitTransVO,operator);
		boolean result=transactionService.handleOneCharge(operator, item.getHouseId(), debitTransVO, creditTransVO);
		if(!result){
			throw new BusinessException("renovate:renovate_add_tran_err",BusinessException.ERROR);
		}
	}

	/**
	 * 功能描述:根据业务类型进行分类，并返回。 key 业务类型 ，value 记录列表<br>
	 * @param chargeRecords<br>
	 * @return
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private Map<String,List<ChargeRecordVO>>  assortChargeRecords(List<ChargeRecordVO> chargeRecords) {
		Map<String,List<ChargeRecordVO>> chargeRecordMap=new HashMap<String, List<ChargeRecordVO>>();
		for(ChargeRecordVO item : chargeRecords){
			if(chargeRecordMap.containsKey(item.getBizType())){
				chargeRecordMap.get(item.getBizType()).add(item);
			}else{
				List<ChargeRecordVO> temp=new ArrayList<ChargeRecordVO>();
				temp.add(item);
				chargeRecordMap.put(item.getBizType(), temp);
			}
		}
		return chargeRecordMap;
	}

	/**
	 * 功能描述:创建一个支付交易VO<br>
	 * @param houseId
	 * @param item
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private CreditTransVO createCreditTran(Long houseId,  Long payBizId,ChargeRecordVO item,DebitTransVO debitTran,Long operator) {
		Long createor = operator;		//创建人ID
		Long businessId = null;		//交易码ID
		BigDecimal sum = null;		//费用金额

		createor = item.getCreator();
		businessId = payBizId;
		sum = item.getSum();

		Set<DebitTransVO> debitTrans=new HashSet<DebitTransVO>();
		debitTrans.add(debitTran);

		CreditTransVO creditTransVO=new CreditTransVO(houseId,businessId,createor,null,sum,debitTrans);
		return creditTransVO;
	}

	/**
	 * 功能描述:创建一个应收交易VO<br>
	 * @param houseId
	 * @param item
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private DebitTransVO createDebitTran(Long houseId,ChargeRecordVO item,Long operator) {
		Long createor = operator;		//创建人ID
		Long businessId = null;		//交易码ID
		BigDecimal sum = null;		//费用金额

		createor = item.getCreator();
		businessId = item.getBusinessId();
		sum = item.getSum();

		DebitTransVO debitTransVO=new DebitTransVO(houseId,businessId,houseId,createor,sum);
		return debitTransVO;
	}

	/**
	 * 功能描述:取得押金抵冲交的交易码<br>
	 * 如果参数预设中未指定，将抛出异常
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-12<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private Long getDepositAGABusinessId() {
		ParameterDefVO business=parameterDefService.findParameterDefByPkey(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_PAY_CODE);
		checkParameterIsNull(business.getPvalue(), "renovate:renovate_deposit_business_none");
		return business.getPvalue();
	}

	/**
	 * 功能描述:装修保证金核算<br>
	 * <ol>
	 * <li>物业收费：</li>
	 * <li>押金抵冲：</li>
	 * <li>押金返还：</li>
	 * <li></li>
	 * </ol>
	 * @param chargeRecordMap<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void handleRenovateDeposit(Long accountHouseId, Long payBizId,Long operator,List<ChargeRecordVO> chargeRecordList) {
		if( null==chargeRecordList ) return ;
		Set<Long> bizIds=new HashSet<Long>();
		for(ChargeRecordVO item : chargeRecordList){
			if( SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY.equals( item.getOperationType()) ){
				addPropertyTran(accountHouseId, payBizId, item, operator);
			}else if(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT_AGA.equals( item.getOperationType())){
				addDepositOffsetTran(payBizId,operator,accountHouseId,item);
			}else if(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_RETURNDEPOSIT.equals( item.getOperationType())){
				ChargeRecordVO temp=new ChargeRecordVO();
				BeanUtil.convertVoAsDo(item, temp);
				temp.setSum( BigDecimal.ZERO.subtract(temp.getSum()));
				addDepositTran(payBizId, operator, accountHouseId,temp);
			}
			bizIds.add(item.getBizId());
		}

		updateDepositAccountingState(bizIds);
		logger.info("装修保证金核算处理完成");
	}

	/**
	 * 功能描述:装修许可证收费<br>
	 * 算法描述：对于装修许可证收费，有两种操作类型：保证金收费、物业收费<br>
	 * 保证金收费：将产生一笔收费交易（保证金帐户）<br>
	 * 物业收费：将产生一笔应收交易和一笔支付交易，金额一样（物业帐户）<br>
	 * 修改许可证收费项目的状态为已收<br>
	 * @param accountHouseId
	 * @param chargeRecordMap<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void handleRenovateLicenceCharge(Long accountHouseId, Long payBizId,Long operator, List<ChargeRecordVO> chargeRecordList) {
		if( null==chargeRecordList ) return ;
		//收集本次操作的所有业务ID，用于后面的状态修改
		//注:一次处理的数据可能存在是多个房间(合并房)的费用,故用MAP分开处理
		Map<Long,List<Long>> bizIds=new HashMap<Long, List<Long>>();//key=房号ID,value=业务ID列表
		for(ChargeRecordVO item : chargeRecordList){
			if( SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT.equals( item.getOperationType()) ){
				addDepositTran(payBizId, operator, accountHouseId,item);
			}else if(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY.equals( item.getOperationType())){
				addPropertyTran(accountHouseId, payBizId, item, operator);
			}

			addBizIds(bizIds, item);
		}
		for(Long houseId : bizIds.keySet()){
			updateRenovateChargeItemState(houseId, bizIds.get(houseId));
		}
		logger.info("装修许可证费用处理完成");
	}

	/**
	 * 功能描述:将业务ID放置MAP中<br>
	 * @param bizIds
	 * @param item<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-19<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void addBizIds(Map<Long, List<Long>> bizIds, ChargeRecordVO item) {
		List<Long> temp=bizIds.get(item.getHouseId());
		if( null==temp ){
			temp=new ArrayList<Long>();
			temp.add(item.getBizId());
			bizIds.put(item.getHouseId(), temp);
		}else{
			temp.add(item.getBizId());
		}
	}

	/**
	 * 功能描述:装修出入证收费<br>
	 * 存在直接入帐与合并入收两种方式<br>
	 * 费用存在物业收费与押金收费两种类型<br>
	 * @param accountHouseId
	 * @param chargeRecordMap<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void handleRenovatePassInCharge(Long accountHouseId, Long payBizId,Long operator, List<ChargeRecordVO> chargeRecordList) {
		if( null==chargeRecordList ) return ;
		List<Long> bizIds = new ArrayList<Long>();
		ChargeRecordVO propertyChargeRecord=null;//合并入帐时物业收费的临时VO，用于累计金额
		ChargeRecordVO depositChargeRecord=null;//合并入帐时保证金的临时VO，用于累计金额
		for(ChargeRecordVO item : chargeRecordList){
			if( SysrefcodeDO.FEE_CHARGE_RECORD_ENTER_ACCOUNT_METHOD_DIRECT.equals(item.getEnterAccountMethod())){
				//直接入帐
					if( SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT.equals( item.getOperationType()) ){
						addDepositTran(payBizId, operator, accountHouseId,item);
					}else if(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY.equals( item.getOperationType())){
						addPropertyTran(accountHouseId, payBizId, item, operator);
					}
					bizIds.add(item.getBizId());
				}else{
				//合并入帐
					if( SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_DEPOSIT.equals( item.getOperationType()) ){
						if( null==depositChargeRecord ){
							depositChargeRecord=new ChargeRecordVO();
							BeanUtil.convertVoAsDo(item, depositChargeRecord);
						}else{
							depositChargeRecord.setSum( depositChargeRecord.getSum().add(item.getSum()) );
							depositChargeRecord.setRemark(depositChargeRecord.getRemark()+";"+item.getRemark());
						}
					}else if(SysrefcodeDO.FEE_CHARGE_RECORD_OPERATION_TYPE_PROPERTY.equals( item.getOperationType())){
						if( null==propertyChargeRecord ){
							propertyChargeRecord=new ChargeRecordVO();
							BeanUtil.convertVoAsDo(item, propertyChargeRecord);
						}else{
							propertyChargeRecord.setSum( propertyChargeRecord.getSum().add(item.getSum()) );
							propertyChargeRecord.setRemark(propertyChargeRecord.getRemark()+";"+item.getRemark());
						}
					}
					bizIds.add(item.getBizId());
				}
		}

		if(null!=propertyChargeRecord){
			addPropertyTran(accountHouseId, payBizId, propertyChargeRecord, operator);
		}
		if(null!=depositChargeRecord){
			addDepositTran(payBizId, operator, accountHouseId,depositChargeRecord);
		}

		updatePassItemState(bizIds);
		logger.info("装修出入证费用处理完成");
	}

	/**
	 * 功能描述:装修出入证退费<br>
	 * 操作成功后，还要更新对应的出入证状态<br>
	 * @param chargeRecordMap<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void handleRenovateReturnCharge(Long accountHouseId, Long payBizId,Long operator,List<ChargeRecordVO> chargeRecordList) {
		if( null==chargeRecordList ) return ;
		List<Long> bizIds = new ArrayList<Long>();
		ChargeRecordVO chargeRecordvo=null;//合并入帐的变量
		for(ChargeRecordVO item : chargeRecordList){
			if( SysrefcodeDO.FEE_CHARGE_RECORD_ENTER_ACCOUNT_METHOD_DIRECT.equals(item.getEnterAccountMethod())){
				//直接入帐
				ChargeRecordVO temp=new ChargeRecordVO();
				BeanUtil.convertVoAsDo(item, temp);
				temp.setSum( BigDecimal.ZERO.subtract(temp.getSum()));
				addDepositTran(payBizId, operator,accountHouseId, temp);
			}else{
				//合并入帐
				if( null==chargeRecordvo){
					chargeRecordvo=new ChargeRecordVO();
					BeanUtil.convertVoAsDo(item, chargeRecordvo);
				}else{
					chargeRecordvo.setSum( chargeRecordvo.getSum().add(item.getSum()));
					chargeRecordvo.setRemark(chargeRecordvo.getRemark()+";"+item.getRemark());
				}
			}
			bizIds.add(item.getBizId());
		}

		if( null!=chargeRecordvo ){
			chargeRecordvo.setSum( BigDecimal.ZERO.subtract(chargeRecordvo.getSum()) );
			addDepositTran(payBizId, operator, accountHouseId,chargeRecordvo);
		}

		updatePassItemReturnState(bizIds);
		logger.info("装修出入证退费处理完成");
	}

	/**
	 * 功能描述:更新核算记录的状态<br>
	 * 装修进程进入完结状态
	 * @param bizIds<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void updateDepositAccountingState(Set<Long> bizIds) {
		for(Long id : bizIds){
			List<Long> ids=new ArrayList<Long>();
			ids.add(id);
			Boolean result=chargeRecordDao.checkFinishHandleYn(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_DEPOSIT,ids);
			if(result){
				DepositAccountingDO depositAccountingDO = depositAccountingDao.findById(id);
				depositAccountingDO.setHandleYn(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);
				depositAccountingDO
				.getInspectionRequisitionDO()
				.getRenovateLicence()
				.getRenovateRequisition()
				.setProcessState(SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_NOR);
			}
		}
	}

	/**
	 * 功能描述:（出入证状态）更新出入证的状态(退费状态：已退)<br>
	 * @param houseId
	 * @param bizIds<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void updatePassItemReturnState(List<Long> bizIds) {
		Map<Long,PassDO> passMap=new HashMap<Long, PassDO>();
		//一次处理将会处理多个出入证，故对其按照出入证进行分类
		for(Long id : bizIds){
			PassChargeItemDO passChargeItemDO = passChargeItemDao.findById(id);
			ParameterDefVO parameterDef= parameterDefService.findParameterDefByPkey(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE);
			checkParameterIsNull(parameterDef.getPvalue(), "renovate:renovate_deposit_businss_none");
			Long businessCode=parameterDef.getPvalue();
			if(businessCode.equals(passChargeItemDO.getItemConfig().getBusinessCode().getKeyword())){
				PassDO passDo=passChargeItemDO.getPass();
				passMap.put(passDo.getKeyword(), passDo);
			}
		}
		//更新退费状态
		for(PassDO pass : passMap.values()){
			List<PassChargeItemDO> chageItemList = passChargeItemDao.getPassChargeItemByPassId(pass.getKeyword());
			List<Long> bizs=new ArrayList<Long>();
			for(PassChargeItemDO item : chageItemList){
				item.setFeeState(SysrefcodeDO.RM_FEE_STATE_RETURN);
				bizs.add(item.getKeyword());
			}
			boolean result=chargeRecordDao.checkFinishHandleYn(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,
					SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_R, bizs);

			if(result){
				pass.setReturnFeeState(SysrefcodeDO.RM_FEE_STATE_RETURN);
			}
		}
	}

	/**
	 * 功能描述:（出入证状态）更新对应的收费项目为已收，及出入证的状态(收费状态：已收，退费状态：未退)<br>
	 * @param houseId
	 * @param bizIds<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void updatePassItemState(List<Long> bizIds) {
		Map<Long,PassDO> passMap=new HashMap<Long, PassDO>();
		for(Long id : bizIds){
			PassChargeItemDO passChargeItemDO = passChargeItemDao.findById(id);
			passChargeItemDO.setFeeState(SysrefcodeDO.RM_FEE_STATE_IN);
			PassDO passDo=passChargeItemDO.getPass();
			passMap.put(passDo.getKeyword(), passDo);
		}

		for(PassDO pass : passMap.values()){
			List<PassChargeItemDO> chageItemList = passChargeItemDao.getPassChargeItemByPassId(pass.getKeyword());
			List<Long> bizs=new ArrayList<Long>();
			for(PassChargeItemDO item : chageItemList){
				bizs.add(item.getKeyword());
			}
			boolean result=chargeRecordDao.checkFinishHandleYn(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,
					SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_CARD_C, bizs);

			if(result){
				pass.setChargeFeeState(SysrefcodeDO.RM_FEE_STATE_IN);
				pass.setReturnFeeState(SysrefcodeDO.RM_FEE_STATE_NO_RETURN);
			}
		}
	}

	/**
	 * 功能描述:更新对应的收费项目为已收，及装修申请的状态<br>
	 * @param houseId
	 * @param bizIds<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void updateRenovateChargeItemState(Long houseId, List<Long> bizIds) {
		for(Long id : bizIds){
			RenovateChargeItemDO renovateChargeItemDO = renovateChargeItemDao.findById(id);
			renovateChargeItemDO.setFeeState(SysrefcodeDO.RM_FEE_STATE_IN);

			Set<RenovateChargeItemDO>  itemList= renovateChargeItemDO.getRenovateRequisition().getRenovateChargeItemDOSet();
			List<Long> itemIds=new ArrayList<Long>();
			for(RenovateChargeItemDO item : itemList){
				itemIds.add(item.getKeyword());
			}

			boolean result=chargeRecordDao.checkFinishHandleYn(SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_MOUDLE_REN,
					SysrefcodeDO.FEE_CHARGE_RECORD_BIZ_TYPE_REN, itemIds);

			if(result){
				RenovateRequisitionDO renovateRequisitionDO= renovateRequisitionDao.getRenovateRequisitionDOByHouseId(houseId);
				renovateRequisitionDO.setFeeState(SysrefcodeDO.RM_FEE_STATE_IN);
			}
		}
	}

	public void setChargeRecordDao(IChargeRecordDao chargeRecordDao) {
		this.chargeRecordDao = chargeRecordDao;
	}

	public void setDepositAccountingDao(IDepositAccountingDao depositAccountingDao) {
		this.depositAccountingDao = depositAccountingDao;
	}

	public void setParameterDefService(IParameterDefService parameterDefService) {
		this.parameterDefService = parameterDefService;
	}

	public void setPassChargeItemDao(IPassChargeItemDao passChargeItemDao) {
		this.passChargeItemDao = passChargeItemDao;
	}

	public void setRenovateChargeItemDao(IRenovateChargeItemDao renovateChargeItemDao) {
		this.renovateChargeItemDao = renovateChargeItemDao;
	}


	public void setRenovateRequisitionDao(IRenovateRequisitionDao renovateRequisitionDao) {
		this.renovateRequisitionDao = renovateRequisitionDao;
	}

	public void setTransactionService(ITransactionService transactionService) {
		this.transactionService = transactionService;
	}

}
